package com.cineplanet.dew.dao;

import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cineplanet.dew.exception.DAOExcepcion;
import com.cineplanet.dew.modelo.Merchandizing;
import com.cineplanet.dew.modelo.Pelicula;

public class MerchandizingDAOImpl extends HibernateDaoSupport  implements MerchandizingDAO {
	
	private DataSource dataSource;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	@Override
	public List<Merchandizing> obtenerMerchandizing(int idPelicula)
			throws DAOExcepcion {
		List<Merchandizing> mercha = new ArrayList<Merchandizing>();
		try {
			mercha = getHibernateTemplate().find("from Merchandizing where id_pelicula = ?",
																 	 String.valueOf(idPelicula));
			
			System.out.println("Metodo obtener Merchandizing: ejecuto normal");
		} catch (Exception e) {
			System.out.println("Metodo obtener Merchandizing: SE CALLO!!!!!!!!!!!!!!!");
			System.out.println("Valor de idPela: " + idPelicula);
			throw new DAOExcepcion(e.getMessage());
		}
		return mercha;
	}

	@Override
	public Merchandizing obtenerMerchandizingUnico(int idMerchandizing)
			throws DAOExcepcion {
		
		Merchandizing mercha = new Merchandizing();
		
		try {
			mercha = (Merchandizing)getHibernateTemplate().find("from Merchandizing where id_producto = ?",
																 	 idMerchandizing).get(0);
		} catch (Exception e) {

			throw new DAOExcepcion(e.getMessage());
		}
		return mercha;
	}

}
